home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / include / incl98.zoo / ctype.h < prev    next >
C/C++ Source or Header  |  1993-11-05  |  3KB  |  96 lines

  1. /*
  2.  *    ctype.h        Character classification and conversion
  3.  */
  4.  
  5. #ifndef _CTYPE_H
  6. #define _CTYPE_H
  7.  
  8. #ifndef _COMPILER_H
  9. #include <compiler.h>
  10. #endif
  11.  
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15.  
  16. extern    unsigned char    *_ctype;
  17.  
  18. #define    _CTc    0x01        /* control character */
  19. #define    _CTd    0x02        /* numeric digit */
  20. #define    _CTu    0x04        /* upper case */
  21. #define    _CTl    0x08        /* lower case */
  22. #define    _CTs    0x10        /* whitespace */
  23. #define    _CTp    0x20        /* punctuation */
  24. #define    _CTx    0x40        /* hexadecimal */
  25.  
  26. #define    isalnum(c)    (_ctype[(unsigned char)(c)]&(_CTu|_CTl|_CTd))
  27. #define    isalpha(c)    (_ctype[(unsigned char)(c)]&(_CTu|_CTl))
  28. #ifndef _POSIX_SOURCE
  29. #define    isascii(c)    !((c)&~0x7F)
  30. #endif /* _POSIX_SOURCE */
  31. #define    iscntrl(c)    (_ctype[(unsigned char)(c)]&_CTc)
  32. #define    isdigit(c)    (_ctype[(unsigned char)(c)]&_CTd)
  33. #define    isgraph(c)    (!(_ctype[(unsigned char)(c)]&(_CTc|_CTs)) && (_ctype[(unsigned char)(c)]))
  34. #define    islower(c)    (_ctype[(unsigned char)(c)]&_CTl)
  35. #define isprint(c)      (!(_ctype[(unsigned char)(c)]&_CTc) && (_ctype[(unsigned char)(c)]))
  36. #define    ispunct(c)    (_ctype[(unsigned char)(c)]&_CTp)
  37. #define    isspace(c)    (_ctype[(unsigned char)(c)]&_CTs)
  38. #define    isupper(c)    (_ctype[(unsigned char)(c)]&_CTu)
  39. #define    isxdigit(c)    (_ctype[(unsigned char)(c)]&_CTx)
  40.  
  41. #define    _toupper(c)    ((c)^0x20)
  42. #define    _tolower(c)    ((c)^0x20)
  43.  
  44. #ifndef _POSIX_SOURCE
  45. #define iswhite(c)    isspace(c)
  46. #define    toascii(c)    ((c)&0x7F)
  47.  
  48. #ifdef __GNUC__
  49. /* use safe versions */
  50.  
  51. #if 0 /* do not define, these are routines in ctype.c as they should be */
  52. #define    toupper(c) \
  53.     ({typeof(c) _c = (c);     \
  54.         islower(_c) ? (_c^0x20) : _c; })
  55. #define    tolower(c)  \
  56.     ({typeof(c) _c = (c);     \
  57.         isupper(_c) ? (_c^0x20) : _c; })
  58. #endif /* 0 */
  59.  
  60. #define toint(c)    \
  61.     ({typeof(c) _c = (c);     \
  62.         (_c <= '9') ? (_c - '0') : (toupper(_c) - 'A' + 10); })
  63. #define isodigit(c) \
  64.     ({typeof(c) _c = (c);      \
  65.         (_c >='0') && (_c<='7'); })
  66. #define iscymf(c)   \
  67.     ({typeof(c) _c = (c);      \
  68.         isalpha(_c) || (_c == '_'); })
  69. #define iscym(c)    \
  70.     ({typeof(c) _c = (c);      \
  71.         isalnum(_c) || (_c == '_'); })
  72.  
  73. #else /* you know what */
  74.  
  75. #if 0 /* see above */
  76. #define    toupper(c)    (islower(c) ? (c)^0x20 : (c))
  77. #define    tolower(c)    (isupper(c) ? (c)^0x20 : (c))
  78. #endif
  79.  
  80. #define toint(c)    ( (c) <= '9' ? (c) - '0' : toupper(c) - 'A' + 10)
  81. #define isodigit(c)    ( (c)>='0' && (c)<='7' )
  82. #define iscymf(c)    (isalpha(c) || ((c) == '_') )
  83. #define iscym(c)    (isalnum(c) || ((c) == '_') )
  84.  
  85. #endif /* __GNUC__ */
  86. #endif /* _POSIX_SOURCE */
  87.  
  88. __EXTERN int    toupper    __PROTO((int));
  89. __EXTERN int     tolower    __PROTO((int));
  90.  
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94.  
  95. #endif /* _CTYPE_H */
  96.